import request from '@/utils/request.js'

const BASE_URL = 'pay/alipay'
// 创建支付订单
export function createAlipayOrder (data) {
  return request({
    url: `${BASE_URL}/create`,
    method: 'POST',
    data
  })
}

// 获取微信支付参数
export function getWxPayParams(orderId) {
  return request({
    url: '/api/payment/wxpay',
    method: 'POST',
    data: { orderId }
  })
}

// 获取支付宝支付参数
export function getAliPayParams(orderId) {
  return request({
    url: '/api/payment/alipay',
    method: 'POST',
    data: { orderId }
  })
}

// 查询支付结果
export function queryPaymentResult(paymentId) {
  return request({
    url: `/api/payment/${paymentId}/status`,
    method: 'GET'
  })
}

// 关闭支付
export function closePayment(paymentId) {
  return request({
    url: `/api/payment/${paymentId}/close`,
    method: 'PUT'
  })
}

// 导出payApi对象
export const payApi = {
  createAlipayOrder,
  getWxPayParams,
  getAliPayParams,
  queryPaymentResult,
  closePayment
} 